package com.example.myapplication.apter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.bumptech.glide.Glide;
import com.example.myapplication.ShuJu.CarouselMapBean;
import com.example.myapplication.ShuJu.CarouselmapSearchBean;

import java.util.List;

public class CarouselmapSearchApter extends PagerAdapter {
    private Context context;
    private List<CarouselmapSearchBean.DataBean> list;
    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    public CarouselmapSearchApter(Context context, List<CarouselmapSearchBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View)object);
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ImageView imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        Glide.with(context).load("http://124.93.196.45:10001"+list.get(position).getImgUrl()).into(imageView);
        container.addView(imageView);
        return imageView;
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return super.getItemPosition(object);
    }
}